import {login} from './service'
import  router  from 'umi/router'
export default {
  namespace: 'login',
  state:{
    isLogin: false,
    data:{},
    content: '',
    modalControl: false,
  },
  effects: {
    * login ({ payload }, { call, put}) {
      yield put({
        type: 'app/getChange',
        payload: {
          requestState: true
        }
      })
      const { data } = yield call(login, payload)
      yield put({
        type: 'app/getChange',
        payload: {
          requestState: false
        }
      })
      yield put({
        type: 'changeLogin',
        payload: {data}
      })
      router.push({
        pathname:'/homePage'
      })
      // yield put({
      //   type: 'modules/getModules',
      //   payload: {
      //     title: '首页',
      //     pathname: '/homePage',
      //     businessId: '1231241201',
      //     // 目前没有定义也没写主页的模块 故不传process 主页写死
      //     process: ''
      //   }
      // })
    }
  },
  reducers: {
    changeLogin (state, { payload }) {
      return {
        ...state,
        isLogin: true,
        ...payload
      }
    },
    changeModal (state, { payload }) {
      return {
        ...state,
        ...payload
      }
    }
    
  }
}